CONTENTS | INDEX | PREV | NEXT
access
NAME
access - determine whether file is accessable
SYNOPSIS
int r = access(filename, mode);
const char *filename;
int mode;
UNIX call
FUNCTION
Returns 0 on success, -1 if no access with the requested modes
may be gained. filename is a pointer to a string that is
the filename we wish to check, modes is a set of modes we
expect the file to be able to do.
the modes may be one or more of the following OR'd together.
0 check for existance of file only
1 check execute permission for file
2 check write permission for file
4 check read permission for file
EXAMPLE
/*
* P.S. this is a dumb, slow, inefficient example
*/
#include <stdio.h>
main(ac, av)
char *av[];
{
char *name;
if (ac == 1) {
puts("Expected a file argument");
exit(1);
}
name = av[1];
if (access(name, 0) == 0) {
puts("it exists");
if (access(name, 1) == 0)
puts("it is executable");
if (access(name, 2) == 0)
puts("I can write to it!");
if (access(name, 4) == 0)
puts("and even read from it!");
} else {
puts("Hmmm, that file does not exist");
}
return(0);
}
INPUTS
char *filename; file to check
int mode; modes as specified above
RESULTS
int r; 0 if modes available, -1 if not
SEE ALSO
open, fopen